<?php

include_once 'lib/redbean/rb.phar';
include_once 'constants.php';
include_once './lib/mail/class.phpmailer.php';

function readFromFile($filename) {
    $fh = fopen($filename, 'r');

    $colleges = array();
    while ($line = fgets($fh)) {
        $colleges[] = $line;
    }
    fclose($fh);
    return $colleges;
}

function sendMail($to, $subject, $msg) {
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->Host = "smtpout.secureserver.net"; //"relay-hosting.secureserver.net";//
    $mail->Port = 80; //465; //465; // or 587
    $mail->IsHTML(true);
    $mail->Username = constant('from_mail'); //"admin@aspiretechnology.in";
    $mail->Password = constant('from_mail_password');//"Confident.1989";
    $mail->SetFrom(constant('set_from')); 
    $mail->Subject = $subject;
    $mail->Body = $msg;
    $mail->AddAddress($to);
    if (!$mail->Send()) {
        return 0;
    } else {
        return 1;
    }
}

function getWishNotificationMail($token,$user_id){
    $mail_content="<!DOCTYPE html>".
                      "<html>".
                            "<body>".
                                "<p>".
                                    "Dear User,</p>".
                                "<p>".
                                "Congratulations on being part of <a href='http://www.bookkad.in'>Bookkad</a>&nbsp;, the best book buying selling portal.</p>".
                                "<p>".
                                    "<a href='http://www.bookkad.in/activate.php?id=$user_id&token=$token'>Click here to activate your account</a>.</p>".
                                "<p>".
                                "Keep in touch.</p>".
                                "<p>".
                                    "<a href='https://www.facebook.com/iambookkad'>Facebook</a></p>".
                                "<p>".
                                    "<a href='https://plus.google.com/b/108731219491992051258/'>Google</a></p>".
                                "<p>".
                                    "<a href='https://twitter.com/Bookkad'>Twitter</a></p>". 
                                "</p>".
                                "<p>".
                                "Thank you,</p>".
                                "<p>".
                                "Start Buying and Selling the books of your choice.</p>".
                                "<p>".
                                "Bookkad Team.</p>".
                                "<p>".
                                "<img alt='' src='http://bookkad.in/images/logo.jpg' style='width: 200px; height: 59px;' /></p>".
                                "<p>".
                                "&nbsp;</p>".
                           "</body>".
                    "</html>";
    return $mail_content;
}
function getActivationMailContent($token,$user_id){
    $mail_content="<!DOCTYPE html>".
                      "<html>".
                            "<body>".
                                "<p>".
                                    "Dear User,</p>".
                                "<p>".
                                "Congratulations on being part of <a href='http://www.bookkad.in'>Bookkad</a>&nbsp;, the best book buying selling portal.</p>".
                                "<p>".
                                    "<a href='http://www.bookkad.in/activate.php?id=$user_id&token=$token'>Click here to activate your account</a>.</p>".
                                "<p>".
                                "Keep in touch.</p>".
                                "<p>".
                                    "<a href='https://www.facebook.com/iambookkad'>Facebook</a></p>".
                                "<p>".
                                    "<a href='https://plus.google.com/b/108731219491992051258/'>Google</a></p>".
                                "<p>".
                                    "<a href='https://twitter.com/Bookkad'>Twitter</a></p>". 
                                "</p>".
                                "<p>".
                                "Thank you,</p>".
                                "<p>".
                                "Start Buying and Selling the books of your choice.</p>".
                                "<p>".
                                "Bookkad Team.</p>".
                                "<p>".
                                "<img alt='' src='http://bookkad.in/images/logo.jpg' style='width: 200px; height: 59px;' /></p>".
                                "<p>".
                                "&nbsp;</p>".
                           "</body>".
                    "</html>";
    return $mail_content;
}
function getForgotPasswordMailContent($password){
    $mail_content="<!DOCTYPE html>".
                      "<html>".
                            "<body>".
                                "<p>".
                                    "Dear User,</p>".
                                "<p>".
                                "Your new password is $password .You can change your password in the edit Profile Section on our website.</p>".
                                "Keep in touch.</p>".
                                "<p>".
                                    "<a href='https://www.facebook.com/iambookkad'>Facebook</a></p>".
                                "<p>".
                                    "<a href='https://plus.google.com/b/108731219491992051258/'>Google</a></p>".
                                "<p>".
                                "Twitter</p>".
                                "<p>".
                                "Thank you,</p>".
                                "<p>".
                                "Start Buying and Selling the books of your choice.</p>".
                                "<p>".
                                "Bookkad Team.</p>".
                                "<p>".
                                "<img alt='' src='http://bookkad.in/images/logo.jpg' style='width: 200px; height: 59px;' /></p>".
                                "<p>".
                                "&nbsp;</p>".
                           "</body>".
                    "</html>";
    return $mail_content;
}
function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}


?>